define (require, exports, module) ->
  # 引入样式
  require 'libs/ztree/zTreeStyle.css'
  # 引入ztree核心库
  require 'libs/ztree/jquery.ztree.core.min.js'
  # 引入ztree复选、单选扩展库
  require 'libs/ztree/jquery.ztree.excheck.min.js'

  # 定义组件
  module.exports = Vue.extend
    # 组件模板
    template: require 'mods/tree_select/tree_select_tpl.js'
    # 组件数据
    data: () ->
      # 是否加载完成
      loadedSucc: false
      # 加载失败提示语
      loadedFail: ''
      # 选中的数据
      checkedItems: []

    # 组件方法
    methods:

      # 插件加载
      pluginLoad: () ->
        self = @

        # 配置选项
        setting =
          check:
            enable: true
            chkboxType:
              "Y": "ps"
              "N": "ps"
          callback:
            onCheck: (event, treeId, treeNode) ->
              # 选中节点的集合
              self.checkedItems = zTreeObj.getCheckedNodes true

        # 数据属性
        zNodes = [
          {
            name: 'test1'
            open: true
            children: [
              { name: 'test1_1' }
              { name: 'test1_2' }
            ]
          }
          {
            name: 'test2'
            open: true
            children: [
              { name: 'test2_1' }
              { name: 'test2_2' }
            ]
          }
        ]
        zTreeObj = $.fn.zTree.init $('#my_ztree'), setting, zNodes

      # 加载成功
      loadedSuccFunc: () ->
        self = @
        self.$nextTick () ->
          # 加载成功标识
          self.loadedSucc = true
          # 插件加载
          self.pluginLoad()

    # 计算属性
    computed:

      # 加载中的样式
      loaddingClass: () ->
        self = @
        if self.loadedSucc
          return 'c-hidden'
        if self.loadedFail
          return 'c-hidden'
        return ''

      # 加载成功的样式
      loadedSuccClass: () ->
        self = @
        return if self.loadedSucc then '' else 'c-vhidden'

      # 加载失败的样式
      loadedFailClass: () ->
        self = @
        return if self.loadedFail then '' else 'c-hidden'

    mounted: () ->
      self = @

      # 加载成功 - 处理函数
      self.loadedSuccFunc()